Using high resolution N-body simulations we have studied the formation and evolution of clusters and groups in a LCDM cosmological model. Groups of galaxies have been formed already before z=4. The total number of small bound systems and the total number of galaxies in these small systems rapidly decreases after z=1.5. The fraction of isolated galaxies remains approximately constant after z =1, whereas the fraction of galaxies in groups decreases. Merging of groups and accretion leads to cluster formation at z < 2. Some of the groups merge into large isolated halos.